package com.yyfax.infrastructure.upgrade;

import android.os.AsyncTask;

/**
 * Created by HenryZhang on 2016/11/23.
 * Copyright © 2016 www.yyfax.com. All Rights Reserved.
 */
public abstract class DownloadIfModifiedTask extends AsyncTask<String, Integer, Object> {
    private static final String DEFAULT_CHARSET = "UTF-8";

    @Override
    protected Object doInBackground(String... params) {
        String url = getDownloadUrl();
		String p = getParams();
        if (url == null && params.length >= 1) url = params[0];
        if (url == null) return null;

        final NetworkPorter.DownloadInfo downloadInfo = NetworkPorter.downloadIfModified(url, p, getCharsetName(), getLocalLastModifiedTime());
        return onDownloadInfo(downloadInfo);
    }

	protected abstract String getParams();

	protected String getDownloadUrl() {
        return null;
    }

    protected String getCharsetName() {
        return DEFAULT_CHARSET;
    }

    protected abstract long getLocalLastModifiedTime();

    protected abstract Object onDownloadInfo(NetworkPorter.DownloadInfo downloadInfo);
}
